clear

capture cd  "/Users/Oliver/Dropbox/Shared/Sent-Down/2008 China survey"




use "china_survey.dta"


**setting sample
    gen urban14=0
        replace urban14=1 if a5>1 &a5!=.
        replace urban14=1 if a9==5 &a5==.
    
    keep  if a1>1945 &a1<1976
    gen birthyear=a1
    replace a1 = 1960.5 - a1 /*flip treatment to the right hand side*/

*pretreatment variables
    recode gender (1=0) (2=1)

    gen minority=a8
        recode minority (1=0) (7=1) 

    gen father_literate=0
        replace father_literate=1 if k1>1
        replace father_literate=. if k1==.

*variables
    egen political_problems=rmean(c1e c1g c1i)
    egen total_problems=rmean(g6* c1a c1b c1c c1d c1f c1h c1j c1k)
    recode c2a (1=5) (2=4) (4=2) (5=1)
    
    gen vote_community = 0,
        replace vote_community = 1 if f2 == 1,
        replace vote_community = . if f2 == .
    recode  e6_a (3=1) (5=0)
        rename  e6_a party_member
    gen ever_contactcadre=0
        replace ever_contactcadre=. if e5b==.
        replace ever_contactcadre=1 if e5b<4

    gen ever_demonstrate=0
        replace ever_demonstrate=. if e5g==.
        replace ever_demonstrate=1 if e5g<4
    gen ever_petition=0
        replace ever_petition=. if e5f==.
        replace ever_petition=1 if e5f<4
    gen any_communitygroup=0
        replace any_communitygroup=1 if e6_g<5|e6_h<5|e6_i<5|e6_j<5
    gen ever_contactcivic=0
        replace ever_contactcivic=. if e5d==.
        replace ever_contactcivic=1 if e5d<4

    recode b7* (1=4)(2=3)(3=2)(4=1)
    recode b9* (1=4)(2=3)(3=2)(4=1)
        egen trust_known = rmean(b7*)
        egen trust_unknown = rmean(b9a b9b b9c b9d b9e b9f)

    recode e9 (1=4)(2=3)(3=2)(4=1)
    recode b11* (5=0)
    recode b13 (1=4)(2=3)(3=2)(4=1)
    recode b12d e14d (1=5)(2=4)(4=2)(5=1)

    gen nationalist=b9i-b9g
        replace nationalist=1 if nationalist>0&nationalist!=.
        replace nationalist=0 if nationalist<=0
        replace nationalist=. if nationalist==.
    gen nonnationalist =.
        replace nonnationalist=1 if nationalist==0
        replace nonnationalist=0 if nationalist==1

    recode g3g (1=5)(2=4)(4=2)(5=1)
